package com.jing.shop.controller;

import com.github.pagehelper.PageInfo;
import com.jing.common.core.domain.R;
import com.jing.common.core.web.controller.BaseController;
import com.jing.shop.domain.dto.ProductBrandDTO;
import com.jing.shop.domain.po.ProductBrandPO;
import com.jing.shop.domain.vo.ProductBrandVO;
import com.jing.shop.service.ProductBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = "商品品牌列表")
@RestController
@RequestMapping("/brand")
public class ProductBrandController {

    private static final Logger log = LoggerFactory.getLogger(ProductBrandController.class);

    @Autowired
    private ProductBrandService productBrandService;

    @ApiOperation("商品品牌列表展示")
    @PostMapping("/page")
    public R page(@RequestBody ProductBrandDTO productBrandDTO){
        PageInfo<ProductBrandPO> productBrandList = productBrandService.findProductBrandList(productBrandDTO);
        return R.ok(productBrandList,"商品品牌列表展示");
    }

    @ApiOperation("商品品牌添加")
    @PostMapping("/add")
    public R add(@RequestBody ProductBrandDTO productBrandDTO){
        productBrandService.addBrand(productBrandDTO);
        return R.ok("添加成功");
    }

    @ApiOperation("商品品牌修改")
    @PostMapping("/update")
    public R update(@RequestBody ProductBrandDTO productBrandDTO){
        productBrandService.updateBrand(productBrandDTO);
        return R.ok("修改成功");
    }

    @ApiOperation("商品品牌批删")
    @GetMapping("/delIds/Ids")
    public R delIds(@PathVariable Integer[] ids){
        productBrandService.delBrandIds(ids);
        return R.ok("批删成功");
    }

    @ApiOperation("商品品牌删除")
    @GetMapping("/del/brandId")
    public R del(@PathVariable Integer brandId){
        productBrandService.delBrandById(brandId);
        return R.ok("删除成功");
    }

    @ApiOperation("商品品牌上传图片")
    @PostMapping("/upload")
    public R upload(@RequestParam("file")MultipartFile multipartFile){
        R upload = productBrandService.upload(multipartFile);
        return upload;
    }

    @ApiOperation("修改制造商状态")
    @PostMapping("/updatebrandFactory")
    public R updatebrandFactory(@RequestBody ProductBrandDTO productBrandDTO){
        productBrandService.updatebrandFactory(productBrandDTO);
        return R.ok();
    }

    @ApiOperation("修改显示状态")
    @PostMapping("/updatebrandShow")
    public R updatebrandShow(@RequestBody ProductBrandDTO productBrandDTO){
        productBrandService.updatebrandShow(productBrandDTO);
        return R.ok();
    }

    @ApiOperation("商品品牌下拉框")
    @GetMapping("/findBrandList")
    public R findBrandList(){
        List<ProductBrandVO> brandList = productBrandService.findBrandList();
        return R.ok(brandList);
    }

}
